/*
 * @Author: yangzonglong
 * @Date: 2021-02-25 14:35:42
 * @version: v1.0.0
 * @Descripttion: 
 * @LastEditors: yangzonglong
 * @LastEditTime: 2021-04-23 09:35:53
 * @Auditor: 
 */
import React, { useMemo, useCallback } from 'react'
import { Checkbox } from 'antd'

const Group = Checkbox.Group;
interface IProps {
  id: string;
  value: boolean | undefined;
  onChange(value: any, id: string): void;
  disabled?: boolean
}

export default ({ value, id, onChange, disabled }: IProps) => {

  const _onChange = useCallback((e) => {
    onChange(e[0] || false, id)
  }, [id, onChange]);

  const handleValue = useMemo(() => {
    if(typeof value === 'boolean') return value;
    return !!value
  }, [value]);

  return (
    <Group disabled={disabled} value={[handleValue]} onChange={_onChange}>
      <Checkbox value={true}></Checkbox>
    </Group>
  )
}